Skip to content

add muse2 main branch install to ci#50

Open
Aurashk wants to merge 9 commits intomainfrom
add-muse2-main-to-ci
Open

add muse2 main branch install to ci#50
Aurashk wants to merge 9 commits intomainfrom
add-muse2-main-to-ci

Conversation

@Aurashk
Copy link
Copy Markdown
Contributor

@Aurashk Aurashk commented Apr 24, 2026

We were only testing the analysis tools against the latest releases of MUSE2 which won't be that frequent - therefore we wanted to also have testing against a build of the current main branch we can run periodically. I have added this to the CI and refactored a bit so it's hopefully easier to follow

Description

Close #25

Type of change

  • Documentation (non-breaking change that adds or improves the documentation)
  • New feature (non-breaking change which adds functionality)
  • Optimization (non-breaking, back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Key checklist

  • All tests pass (eg. python -m pytest)
  • Pre-commit hooks run successfully (eg. pre-commit run --all-files)

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added or an issue has been opened to tackle that in the future.
    (Indicate issue here: # (issue))

organise CI flow to be easier to follow
Copilot AI review requested due to automatic review settings April 24, 2026 12:48
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.61%. Comparing base (790a01a) to head (dd6004c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #50   +/-   ##
=======================================
  Coverage   47.61%   47.61%           
=======================================
  Files           3        3           
  Lines          42       42           
  Branches        4        4           
=======================================
  Hits           20       20           
  Misses         22       22           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds CI coverage for testing this repository against both the latest MUSE2 release and a build from the MUSE2 main branch, factoring the setup/verification logic into reusable workflows and composite actions.

Changes:

  • Refactors CI to call a reusable workflow that runs the test matrix against a selected MUSE2 source (release or main).
  • Adds composite actions to (a) install MUSE2 from the latest release, (b) build/install MUSE2 from main, and (c) verify MUSE2_PATH is set.
  • Updates the main CI workflow to run both “release” and “main” test suites.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
.github/workflows/test-with-muse2.yml New reusable workflow that installs deps, sets up MUSE2 (main/release), verifies, runs pytest, and uploads coverage for release/Linux.
.github/workflows/ci.yml Refactors CI to run two jobs (release + main) via the reusable workflow.
.github/actions/verify-muse2/action.yml New composite action to validate MUSE2_PATH.
.github/actions/setup-muse2-release/action.yml New composite action to download/extract latest MUSE2 release asset and set MUSE2_PATH.
.github/actions/setup-muse2-main/action.yml New composite action to cargo install MUSE2 from the main branch and set MUSE2_PATH.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +45 to +49
- name: Setup MUSE2 from main
if: inputs.muse2_source == 'main'
uses: ./.github/actions/setup-muse2-main
with:
muse2_exe: ${{ matrix.muse2_exe }}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because MUSE2 setup is entirely conditional on inputs.muse2_source, any unexpected value will skip both setup steps and then fail later in verify-muse2 with a misleading “executable not found” error. Consider adding an explicit validation step early in the job (and a clear error message) to enforce allowed values (e.g. main/release).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unlikely to come up but I added a check anyway

Comment thread .github/workflows/test-with-muse2.yml
Comment thread .github/actions/verify-muse2/action.yml
Comment thread .github/actions/verify-muse2/action.yml
Comment thread .github/actions/setup-muse2-main/action.yml Outdated
Comment thread .github/workflows/ci.yml
Comment on lines +17 to +22
test_main:
name: Test against MUSE2 main
uses: ./.github/workflows/test-with-muse2.yml
with:
muse2_source: main
secrets: inherit
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a full “build MUSE2 from main” test job to the standard CI on every push/PR, but the PR description/issue calls out running the main-branch build periodically. If the intent is periodic coverage, consider gating test_main behind a schedule/manual trigger (or making it conditional) to avoid significantly increasing CI duration and external network/build load on every PR.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably need this in PR's too though?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we def want it for PRs, but it would be good to also run this every week or so. We have an issue for this (#43) and I've taken the liberty of assigning you to it just now 😉.

You just need to add a cron trigger for the workflow.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do this in this PR while you're at it? It's just a small change to this file.

Copilot AI review requested due to automatic review settings April 24, 2026 14:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/test-with-muse2.yml
@alexdewar
Copy link
Copy Markdown
Member

Is this ready for review?

@Aurashk Aurashk requested a review from alexdewar April 27, 2026 09:29
@Aurashk
Copy link
Copy Markdown
Contributor Author

Aurashk commented Apr 27, 2026

Is this ready for review?

Should be, although I'm just going through the copilot responses now.

Also, I'm not totally understanding what those three pending checks are in the CI, I remember seeing it before and it blocking merging.

@alexdewar
Copy link
Copy Markdown
Member

Is this ready for review?

Should be, although I'm just going through the copilot responses now.

Ok cool. I'll hold off reviewing for a mo until you've had a look at those then.

Also, I'm not totally understanding what those three pending checks are in the CI, I remember seeing it before and it blocking merging.

They're there because they're the ones that are required for merging. If you change the names of the checks, then you'll see the names of the old ones there forever. It's fine. Once I've reviewed this and it's ready to merge, we can update the list of required checks.

Aurashk added 2 commits April 27, 2026 10:50
add early checks for muse2_source compatiable string and codecov token is present
Copilot AI review requested due to automatic review settings April 27, 2026 10:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/test-with-muse2.yml Outdated
Comment on lines +10 to +12
secrets:
CODECOV_TOKEN:
required: false
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODECOV_TOKEN is declared as optional (required: false) for workflow_call, but the workflow later treats it as mandatory on Linux release runs. Either mark the secret as required, or make coverage upload conditional on the token being present (so forks/other callers without the secret can still run tests).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it required so it fails early without it

Comment thread .github/workflows/test-with-muse2.yml Outdated
run: |
cargo install \
--git https://github.com/EnergySystemsModellingLab/MUSE2 \
--branch main \
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo install from a git repo should generally be run with --locked to ensure the build uses the repo's Cargo.lock (and fails if it's out of date) rather than implicitly updating dependencies, which can make CI flaky and less reproducible.

Suggested change
--branch main \
--branch main \
--locked \

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems sensible ?

Comment thread .github/workflows/ci.yml
@@ -1,4 +1,4 @@
name: Test and build
name: Test against MUSE2
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR/issue description mentions running the MUSE2-main build periodically, but ci.yml doesn't add a schedule trigger (it only runs on push/PR/manual). Either add a cron schedule for the main-branch job or adjust the description/issue expectations.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 27, 2026 10:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/actions/verify-muse2/action.yml Outdated
Comment on lines +45 to +53
- name: Setup MUSE2 from main
if: inputs.muse2_source == 'main'
uses: ./.github/actions/setup-muse2-main
with:
muse2_exe: ${{ matrix.muse2_exe }}

- name: Setup MUSE2 from latest release
if: inputs.muse2_source == 'release'
uses: ./.github/actions/setup-muse2-release
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

muse2_source controls which setup step runs, but the workflow never validates the input. Any unexpected value will skip both setup steps and then fail in verify-muse2 with a misleading “executable not found” error. Add an explicit validation step early in the job to enforce allowed values (e.g. main/release) and emit a clear error message before proceeding.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there doesn't seem to be a nice way to do this within actions scripts, and I don't think it's super likely to cause an issue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is fine.

@Aurashk
Copy link
Copy Markdown
Contributor Author

Aurashk commented Apr 27, 2026

Is this ready for review?

Should be, although I'm just going through the copilot responses now.

Ok cool. I'll hold off reviewing for a mo until you've had a look at those then.

Also, I'm not totally understanding what those three pending checks are in the CI, I remember seeing it before and it blocking merging.

They're there because they're the ones that are required for merging. If you change the names of the checks, then you'll see the names of the old ones there forever. It's fine. Once I've reviewed this and it's ready to merge, we can update the list of required checks.

all good now whenever you're ready

Copy link
Copy Markdown
Member

@alexdewar alexdewar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I've suggested a few tweaks.

cargo install \
--git https://github.com/EnergySystemsModellingLab/MUSE2 \
--branch main \
--root "$GITHUB_WORKSPACE/muse2_cargo_root" \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the --root option needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the alternative is to point MUSE2_PATH at wherever the default root is instead ($HOME/.cargo/?), I don't have too much of a preference if you think that's better

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see! Well, I think cargo will install muse2 so that it's on the PATH and then the code will be able to find it directly, without you having to set MUSE2_PATH. See:

path = os.getenv("MUSE2_PATH") or shutil.which("muse2")

I think that would be slightly cleaner.

shell: pwsh
run: |
$exePath = "${{ github.workspace }}\muse2_cargo_root\bin\${{ inputs.muse2_exe }}"
echo "MUSE2_PATH=$exePath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the bash shell on Windows too btw. I'm not sure about passing the exe file name to this Action though. I feel like it should "know" that it needs a .exe extension for Windows. Same for the other Action.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my resistance to this is that you would have to update the exe name in multiple places if we ever changed it for some reason... Not that that would be too cumbersome though, do you prefer just having the actual names if the os branches rather than inputs.muse2_exe?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you take my suggestion above, I don't think you'll need the name of the muse2 exe at all.

Comment on lines +17 to +26
TAG=$(curl -sSf \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ inputs.github_token }}" \
https://api.github.com/repos/EnergySystemsModellingLab/MUSE2/releases/latest \
| jq -r '.tag_name')

if [[ -z "$TAG" || "$TAG" == "null" ]]; then
echo "::error::Failed to retrieve latest MUSE2 release tag."
exit 1
fi
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do all this stuff with the gh command, which is included with the default runners. The only thing is that I'm not sure if the GitHub token will be passed to it automatically for an Action (it is for workflows, via an env var).

This could all be done with:

gh release list --json name,isLatest --jq '.[] | select(.isLatest)|.name'

I'd be tempted to try it and, if it doesn't work, then you can figure out how to pass the token (I think you just set the GITHUB_TOKEN env var).

Comment on lines +34 to +36
curl -sSfL \
"https://github.com/EnergySystemsModellingLab/MUSE2/releases/download/${{ steps.muse2_release.outputs.tag }}/${{ runner.os == 'Windows' && 'muse2_windows.zip' || runner.os == 'macOS' && 'muse2_macos_arm.tar.gz' || 'muse2_linux.tar.gz' }}" \
--output "muse2_asset_download"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly this could be:

gh release download $TAG

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(with some extra flags)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much nicer, you don't even need the tag step anymore because it uses the latest release by default

Comment thread .github/workflows/ci.yml
Comment on lines +17 to +22
test_main:
name: Test against MUSE2 main
uses: ./.github/workflows/test-with-muse2.yml
with:
muse2_source: main
secrets: inherit
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we def want it for PRs, but it would be good to also run this every week or so. We have an issue for this (#43) and I've taken the liberty of assigning you to it just now 😉.

You just need to add a cron trigger for the workflow.

Comment on lines +45 to +53
- name: Setup MUSE2 from main
if: inputs.muse2_source == 'main'
uses: ./.github/actions/setup-muse2-main
with:
muse2_exe: ${{ matrix.muse2_exe }}

- name: Setup MUSE2 from latest release
if: inputs.muse2_source == 'release'
uses: ./.github/actions/setup-muse2-release
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is fine.

Copilot AI review requested due to automatic review settings April 27, 2026 11:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +13
secrets:
CODECOV_TOKEN:
required: true

Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODECOV_TOKEN is marked as a required secret for the reusable workflow. Because required workflow_call secrets are enforced at invocation time (even when the Codecov step is skipped), this makes all callers (including the muse2_source: main run) require the token and will cause CI to fail for PRs from forks where secrets aren’t available. Consider making CODECOV_TOKEN optional and additionally gating the Codecov upload step on the token being present (or moving coverage upload to a separate workflow that’s only invoked for release).

Copilot uses AI. Check for mistakes.
@Aurashk Aurashk requested a review from alexdewar April 28, 2026 09:02
Copy link
Copy Markdown
Member

@alexdewar alexdewar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've suggested a few more small things.

cargo install \
--git https://github.com/EnergySystemsModellingLab/MUSE2 \
--branch main \
--root "$GITHUB_WORKSPACE/muse2_cargo_root" \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see! Well, I think cargo will install muse2 so that it's on the PATH and then the code will be able to find it directly, without you having to set MUSE2_PATH. See:

path = os.getenv("MUSE2_PATH") or shutil.which("muse2")

I think that would be slightly cleaner.

shell: pwsh
run: |
$exePath = "${{ github.workspace }}\muse2_cargo_root\bin\${{ inputs.muse2_exe }}"
echo "MUSE2_PATH=$exePath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you take my suggestion above, I don't think you'll need the name of the muse2 exe at all.

Comment thread .github/workflows/ci.yml
Comment on lines +17 to +22
test_main:
name: Test against MUSE2 main
uses: ./.github/workflows/test-with-muse2.yml
with:
muse2_source: main
secrets: inherit
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do this in this PR while you're at it? It's just a small change to this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add main muse2 branch to CI

4 participants